/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

/**
 *
 * @author kylin
 */
public class TestThreadJoin {
    public static void main(String args[]){
        MyThread3 th1=new MyThread3("th1");
        th1.start();
        try{
            th1.join();//相当于方法调用;main线程调用了th1线程的join()方法，main线程必须等th1线程执行结束才会向下执行
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        for(int i=1;i<=10;i++){
            System.out.println("I am main thread");
        }
    }
}

class MyThread3 extends Thread{
    MyThread3(String s){
        super(s);
    }
    public void run(){
        for(int i=1;i<=10;i++){
            System.out.println("I am "+this.getName());
            try{
                sleep(1000);
            }catch(InterruptedException e){
                return;
            }
        }
    }
}